#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# author: maxiao
# date: 2023-03-10 20:44
# description: 测试装饰器的功能


def say(info):
    def decorate(*arg):
        print("hello world")
        info(*arg)
        print('done!')
    return decorate
        

@say
def info(name):
    print(f"hi {name}") 


@say
def show():
    print("我会python shell linux等专业技能")
    print('666')


info('maxiao')
print()
show()


single = {}

def singelton(obj):
    def on_call(*args, **kwargs):
        if obj not in single:
            single[obj] = obj(*args, **kwargs)
        return single[obj]
    return on_call


@singelton
class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def display(self):
        print(self.name, '--->', self.age)

# 测试装饰器
p1 = Person('111', 11)
p2 = Person('222', 22)
print()
# 测试单例模式
p1.display()
p2.display()

